package com.jjyu.controller;

import com.jjyu.entity.FavoriteRestaurant;
import com.jjyu.service.impl.FavoriteRestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/favorites")
public class FavoriteRestaurantController {

    @Autowired
    private FavoriteRestaurantService favoriteRestaurantService;

    @PostMapping
    public ResponseEntity<String> addFavorite(@RequestBody FavoriteRestaurant favoriteRestaurant) {
        favoriteRestaurantService.addFavorite(favoriteRestaurant);
        return ResponseEntity.ok("餐厅已添加到收藏");
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<String> removeFavorite(@PathVariable Integer id) {
        favoriteRestaurantService.removeFavorite(id);
        return ResponseEntity.ok("收藏的餐厅已移除");
    }

    @GetMapping("/user/{userId}")
    public ResponseEntity<List<FavoriteRestaurant>> getUserFavorites(@PathVariable Integer userId) {
        List<FavoriteRestaurant> favorites = favoriteRestaurantService.getFavoritesByUserId(userId);
        return ResponseEntity.ok(favorites);
    }
}
